#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct BTNode{
	char data;
	struct BTNode *Left;
	struct BTNode *right;
}BTNODE,*BT;
BT create(char a[],char b[],int len){
	BT pT;
	int i;
	if(len==0){
		return NULL;
	}
	else{ 
		pT=(BT)malloc(sizeof(BTNODE));
		pT->data=a[0];
		for(i=0;i<len;i++){
			if(b[i]==a[0])
				break;
		}
		pT->Left=create(a+1,b,i);
		pT->right=create(a+1+i,b+1+i,len-i-1);
	}
	return pT;
}
int height(BT pT){
	int max,Lhight,Rhight;
	if(pT!=NULL){
		Lhight=height(pT->Left);
		Rhight=height(pT->right);
		max=Lhight>=Rhight?Lhight:Rhight;
		max++;
	}
	return max;
}
int main(){
	BT pT;
	int n;
	scanf("%d",&n);
	char s1[n],s2[n];
	getchar();
	scanf("%s",&s1);
	getchar();
	scanf("%s",&s2);
	int len=strlen(s1);
	pT=create(s1,s2,len);
	printf("%d",height(pT));
	return 0;
} 
